home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ May 89 / U0040-view hierarchy --> -May89 < prev    next >
Encoding:
Text File  |  1989-06-26  |  3.8 KB  |  115 lines  |  [TEXT/GEOL]

  1. Item    5893594                         18-May-89        13:29
  2.  
  3. From:   STONECUTTER                     Stonecutter SW, Don Sawtelle, PRT
  4.  
  5. To:     D0420                           Satori SW, Hugh Rogovy, PRT
  6.  
  7. cc:     MACDTS                          Macintosh Developer Technical Supt.
  8.         MACAPP.TECH$                    MACAPP Tech
  9.  
  10. Sub:    view hierarchy --> 'view' rsrc
  11.  
  12. To: D0420, MACDTS, MACAPP.TECH$
  13. In response to: "How to use WriteRes????" From Chris Le Croy, Satori Software
  14.  
  15. Chris writes:
  16.  
  17. >> Does anyone know how to use the WriteRes methods?  I haven't been able to
  18. >> find it documented anywhere, except for very brief mentions
  19.  
  20. Chris,
  21.  
  22. At the end of this message I've included an edited excerpt of code which may be
  23. helpful as an example of how to save a view hierarchy as a resource.
  24.  
  25. This example saves the view hierarchies contained by each of a document's
  26. windows as 'view' resources in the resource fork of a document file. This works
  27. because I call IDocument with the kUsesRsrcFork and kRsrcOpen flags. Perhaps
  28. there are hidden pitfalls in doing that--but it's worked so far for me.
  29.  
  30. Please don't expect it to be more than an example. I quickly edited out code
  31. which is not relevant, and  have not tested it since. It may contain old bugs,
  32. new bugs, reflect my ignorance, horrible errors in judgement, etc., etc.
  33.  
  34. Also, it is specific to our project. For instance, it saves only the view
  35. hierarchy in the window--not the window itself--and assumes that each window
  36. contains exactly one subview (though that view may contain any number of
  37. subviews itself, ad infinitum.)
  38.  
  39. You may wish to write a more general version which tests whether the window has
  40. any subviews, and works no matter how many there are. It'd be great if you
  41. would post a description of your experiences (and example source) back to
  42. MacApp.Tech$.
  43.  
  44. If anyone in MacApp.Tech$ or MacDTS knows more about this or can point out
  45. errors or add additional information, _please post a note to MacApp.Tech$
  46. Perhaps the current programmers of ViewEdit would like to comment? Surely you
  47. guys are the most knowledgeable on this topic.
  48.  
  49. Hope this helps,
  50.  
  51. Don Sawtelle
  52. Applelink: Stonecutter
  53. (415) 851-5665
  54.  
  55. Stonecutter Software (contract Mac software development/consulting)
  56. 47 Skylonda Drive
  57. Woodside, CA 94062-3721
  58.  
  59. {---------------------------------------------------------------------------}
  60. PROCEDURE TMyDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
  61.   VAR
  62.     theWindow: TWindow;
  63.     aHandle: ViewRsrcHndl;
  64.     p: Ptr;
  65.     rsrcNumber: Integer;
  66.  
  67.   PROCEDURE SaveSubview( theView: TView );
  68.     BEGIN
  69.       IF (theView <> NIL) THEN
  70.         BEGIN
  71.           theView.WriteRes( aHandle, p );
  72.           IF theView.CountSubViews > 0 THEN
  73.             theView.fSubviews.Each( SaveSubview );
  74.         END
  75.     END;
  76.  
  77.   PROCEDURE SaveWindowContents( theWindow: TWindow );
  78.     VAR
  79.       singleSubView: TView;
  80.       aStr255: Str255;
  81.     BEGIN
  82.       { Warning: this code assumes the window contains a single subview }
  83.       { of type TScreen (which can in turn contain subviews of any type.) }
  84.       { Your app may need this changed so that it works when a window contains
  85. }
  86.       { any number (0 to n) of subviews. }
  87.  
  88.       singleSubView := TView( theWindow.fSubViews.First );
  89.  
  90.       aHandle := NewViewRsrc( p );
  91.       singleSubView.WriteRes( aHandle, p );
  92.  
  93.       IF singleSubView.CountSubViews > 0 THEN
  94.         singleSubView.fSubviews.Each( SaveSubview );
  95.  
  96.       DoneViewRsrc( aHandle, p );
  97.  
  98.       AddResource( Handle(aHandle), 'view', rsrcNumber, 'Test!' );
  99.       WriteResource( Handle(aHandle) );
  100.       FailOSErr(ResError);
  101.  
  102.       rsrcNumber := rsrcNumber + 1;
  103.     END;
  104.  
  105.   {.............................................................}
  106.   BEGIN
  107.     Inherited DoWrite(aRefNum, makingCopy);
  108.  
  109.     rsrcNumber := 1;
  110.     self.fWindowList.Each( SaveWindowContents );
  111.   END;
  112.  
  113.  
  114.  
  115.